package com.gestocasa.model;

import java.util.UUID;

public class Descriptor implements Comparable<Descriptor> {

	private int id;
	private UUID internalId;
	private String name;
	private String value;
	private int order;
	
	public Descriptor() {
		this(null);
	}
	
	public Descriptor(Descriptor d) {
		if(d == null) {
			id = -1;
			internalId = UUID.randomUUID();
			name = "";
			value = "";
			order = 0;
		}
		else {
			id = d.getId();
			internalId = d.getInternalId();
			name = d.getName();
			value = d.getValue();
			order = d.getOrder();
		}
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public UUID getInternalId() {
		return internalId;
	}

	public void setInternalId(String internalId) {
		setInternalId((internalId == null) ? UUID.randomUUID() : UUID.fromString(internalId));
	}
	
	public void setInternalId(UUID internalId) {
		this.internalId = internalId;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	@Override
	public int compareTo(Descriptor o) {
		if(order == o.getOrder()) {
			if(name == null || o.getName() == null) {
				return 0;
			}
			else {
				return name.compareTo(o.getName());
			}
		}
		else {
			if(order < o.getOrder()) {
				return -1;
			}
			else if(order > o.getOrder()) {
				return 1;
			}
			else {
				return 0;
			}
		}
	}
}
